<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Section 11.4.&nbsp; Calling System Calls</title>
<link rel="STYLESHEET" type="text/css" href="images/style.css">
<link rel="STYLESHEET" type="text/css" href="images/docsafari.css">
<script type="text/javascript"><!--
google_ad_client = "pub-0203281046321155";
google_alternate_ad_url = "http://www.bookhtml.com/adbrite.htm";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="4867465545";
google_color_border = "FFFFFF";
google_color_link = "0000FF";
google_color_bg = "FFFFFF";
google_color_text = "000000";
google_color_url = "0000FF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=learnphpmysql-CHP-11-SECT-3.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=learnphpmysql-CHP-11-SECT-5.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
<br><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><a name="learnphpmysql-CHP-11-SECT-4"></a>
<h3 id="631368-945" class="docSection1Title">11.4. Calling System Calls</h3>
<a name="IDX-CHP-11-0578"></a> 
<a name="IDX-CHP-11-0579"></a> 

<p class="docText">A system call is used by an application to request service from the operating system. System calls use machine code instructions, which causes the processor to change modes. Changing the mode gets the OS to perform restricted actions; for example, accessing hardware devices or server space available.</p>
<p class="docText">Every OS provides a library that sits between normal programs and the rest of the operating system, such as the Windows API. This library handles low-level details of passing information to the kernel and switching to supervisor mode.</p>
<p class="docText">You can use the <tt>exec</tt> function to call external functions.</p>
<p><table border="0" bgcolor="black" cellspacing="0" cellpadding="1" width="90%" align="center"><tr><td><table bgcolor="white" width="100%" border="0" cellspacing="0" cellpadding="6"><tr><td width="60" valign="top"><img src="images/warning_yellow.jpg" width="51" height="36" alt=""></td><td valign="top">
<p class="docText">For maximum security, use <tt>exec</tt> only when PHP code doesn't provide the same functionality.</P>
</td></tr></table></TD></TR></table></p><BR>
<p class="docText">For example, if you'd like to get information about how much space is available on the server, execute the <tt>df</tt> command, shown in <a class="docLink" href="#learnphpmysql-CHP-11-EX-29">Example 11-29</a>. However, this is assuming you're on a Unix host.</p>
<a name="learnphpmysql-CHP-11-EX-29"></a><h5 id="title-IDAM05LM" class="docExampleTitle">Example 11-29. Executing df and displaying the results</h5><P><table cellspacing="0" width="90%" border="1" cellpadding="5"><tr><td>

<pre>
&lt;?php
exec("df",$output_lines,$return_value);
echo ("Command returned a value of $return_value.");
echo "&lt;/pre&gt;";
foreach ($output_lines as $output) {
  echo "$o";
}
echo "&lt;/pre&gt;";
?&gt;
</pre><BR>

</td></tr></table></P>
<p class="docText">For our system, we get the screen in <a class="docLink" href="#learnphpmysql-CHP-11-FIG-23">Figure 11-23</a>.</p>
<a name="learnphpmysql-CHP-11-FIG-23"></a><p><center>
<h5 class="docFigureTitle">Figure 11-23. A synopsis of how full the hard disk is, from PHP</h5>
<img border="0" alt="" id="195131084204" width="549" height="223" SRC="images/learnphpmysql_1123.jpg">
</center></P><BR>
<p><table border="0" bgcolor="black" cellspacing="0" cellpadding="1" width="90%" align="center"><tr><td><table bgcolor="white" width="100%" border="0" cellspacing="0" cellpadding="6"><tr><TD width="60" valign="top"><img src="images/warning_yellow.jpg" width="51" height="36" alt=""></td><TD valign="top">
<p class="docText">Use extreme caution! Remember that while linking other commands in this chapter, you should avoid passing user input to <tt>exec</tt> because there's a substantial risk for misuse.</p>
</TD></TR></table></TD></tr></table></p><br>
<p class="docText">We're now going to discuss modifying objects in MySQL and working with data using PHP.</p>

</TD></TR></table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=learnphpmysql-CHP-11-SECT-3.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=learnphpmysql-CHP-11-SECT-5.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
</body></html>
